﻿using System;
using System.Threading;
using ZeroMQ;
using System.Text;

namespace Ayatta.Auction.Notifier
{
    public class WinService
    {
        //private static readonly Thread thread = new Thread(StartSocket);
       
        //public void Start()
        //{
          
        //    thread.Start();
        //}
        public void Start()
        {
            try
            {
                using (var context = ZmqContext.Create())
                using (ZmqSocket subscriber = context.CreateSocket(SocketType.SUB), publisher = context.CreateSocket(SocketType.PUB))
                {
                    //  This is where the weather server sits
                    subscriber.Connect("tcp://127.0.0.1:4444");
                    subscriber.SubscribeAll();
                    //  This is our public endpoint for subscribers
                    publisher.Bind("tcp://*:3333"); // i use local to be able to run the example, this could be the public ip instead eg. tcp://10.1.1.0:8100

                    //  Shunt messages out to our own subscribers
                    while (true)
                    {
                        var data = subscriber.Receive(Encoding.UTF8);
                        if (!string.IsNullOrEmpty(data))
                        {
                            Console.WriteLine(data);
                            publisher.Send(data, Encoding.UTF8);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                //Console.Write(e.Message);
                //Console.ReadLine();
            }
        }
        

        public void Stop()
        {
          
        }
    }
}